package util

import (
	"encoding/json"
	"log"
	"net/http"
)

type H struct{
	Code int `json:"code""`
	Data interface{} `json:"data,omitempty"`
	Msg string	`json:"msg"`
}
func Resp(w http.ResponseWriter,code int ,data interface{},msg string){
	w.Header().Set("Content-Type","application/json")
	w.WriteHeader(http.StatusOK)
	h:=H{
		Code: code,
		Data: data,
		Msg:  msg,
	}
	str,err:=json.Marshal(h)
	if err!=nil {
		log.Println(err.Error())
	}
	w.Write([]byte(str))
}
func RespFail(w http.ResponseWriter,msg string){
	 Resp(w ,-1 ,nil,msg)
}
func RespOk(w http.ResponseWriter,data interface{},msg string){
	Resp(w,0,data,msg)
}
